﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShareMarking.Systems.Service;
using ShareMarking.Service;
using ShareMarking.Entity;
using System.Data;
using MySoft.Data;
using Common.Utilities.Excel.Export;
using System.IO;
using Common.Utilities.Excel;
using System.Net;
using System.Drawing.Imaging;
using ShareMarking.Services;
using ShareMarking.Interface;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Text;

namespace ShareMarking.Web.admin.EnterPrise.Activity
{
    public partial class List : ManagePage
    {
        private static string httpstr = ConfigurationManager.AppSettings["vigohttp"];
        private static string signsecret = ConfigurationManager.AppSettings["signscrect"];
        private static string diyhttp = ConfigurationManager.AppSettings["diyhttp"];//本系统网站域名

        #region 参数配置=================================

        protected int totalCount;
        protected int page;
        protected string A_Name = string.Empty;//活动名称
        protected string A_Manager = string.Empty;//活动负责人
        protected string isSenate = string.Empty;//是否带参
        protected string pageSizeCookieKey = "qr_Activity_index_page_size";//当前页的每页大小的cookiekey
        protected int pageSize
        {
            get
            {
                int _default_size = 10;
                int _pagesize;
                if (int.TryParse(Utils.GetCookie(pageSizeCookieKey), out _pagesize))
                {
                    if (_pagesize > 0)
                    {
                        return _pagesize;
                    }
                }
                return _default_size;
            }
        }
        protected string orderBy = "qr_Activity.ActivityID desc";

        protected string keywords = string.Empty;
        protected string searchURL { get { return Utils.CombUrlTxt("List.aspx", "A_Name={0}&A_Manager={1}&isSenate={2}", this.A_Name, this.A_Manager, this.isSenate); } }

        #endregion

        #region 初始化===================================

        protected void Page_Load(object sender, EventArgs e)
        {
            //检查权限
            //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.View.ToString());

            //初始化搜索参数
            this.keywords = DTRequest.GetQueryString("keywords");
            this.A_Name = DTRequest.GetQueryString("A_Name");
            this.A_Manager = DTRequest.GetQueryString("A_Manager");
            this.isSenate = DTRequest.GetQueryString("isSenate");
            //this.A_wxQrCodeID = DTRequest.GetQueryInt("A_wxQrCodeID");
            if (!Page.IsPostBack)
            {
                //绑定下拉框的值

                //绑定列表
                RptBind();
            }
        }

        #endregion

        #region 绑定下拉框===============================

        #endregion

        #region 绑定列表=================================
        private void RptBind()
        {
            this.page = DTRequest.GetQueryInt("page", 1);
            
            //获取数据源            
            if (!A_Name.IsNullOrEmpty())
            {
                this.txtA_Name.Text = A_Name;
            }
            if (!A_Manager.IsNullOrEmpty())
            {
                this.txtA_Manager.Text = A_Manager;
            }
            if (!isSenate.IsNullOrEmpty())
            {
                if (isSenate.ToLower() == "true" || isSenate.ToLower() == "false")
                {
                    this.ddl_IsSenate.SelectedValue = isSenate;
                }
            }
            else
            {
                isSenate = "true";
            }

            if (isSenate == "true")
            {
                this.rptList.DataSource = qr_ActivityService.Instance.Get_qr_Activity_PageSelect(page, pageSize, orderBy, out totalCount, A_Name, A_Manager, isSenate);
                this.rptList.DataBind();
            }
            else if (isSenate == "false")
            {
                this.rptList2.DataSource = qr_ActivityService.Instance.Get_qr_Activity_PageSelect(page, pageSize, orderBy, out totalCount, A_Name, A_Manager, isSenate);
                this.rptList2.DataBind();
            }
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = ComLib.UrlHelper.Instance.SetUrl(searchURL).AddParam("page", "__id__").GetAddedParamUrl();
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
        #endregion

        #region 搜索操作=================================

        //关健字查询
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.keywords = txtKeywords.Text;
            Response.Redirect(searchURL);
        }
        //关健字查询
        protected void btnDetailedSearch_Click(object sender, EventArgs e)
        {
            this.A_Name = txtA_Name.Text;
            this.A_Manager = txtA_Manager.Text;
            Response.Redirect(searchURL);
        }

        //筛选类别
        //设置分页数量
        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie(pageSizeCookieKey, _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect(searchURL);
        }

        #endregion

        #region 删除操作=================================

        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            //检查权限
            //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.Delete.ToString());

            int sucCount = 0;
            int errorCount = 0;
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    if (qr_ActivityService.Instance.Delete_Entity(qr_Activity._.ActivityID == id))
                    {
                        sucCount += 1;
                    }
                    else
                    {
                        errorCount += 1;
                    }
                }
            }

            //记录日志
            AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "删除qr_Activity" + sucCount + "条，失败" + errorCount + "条");

            JscriptMsg("删除成功" + sucCount + "条，失败" + errorCount + "条！", searchURL, "Success");
        }

        #endregion

        #region 生成微信二维码===========================
        public string geturl(string sceneid)
        {
            var qrcode = qr_QrCodeService.Instance.Get_SingleEntity_byWhere(qr_QrCode._.scene_id == sceneid);
            if (qrcode != null)
                return qrcode.qrcode_url;
            return "";
        }
        #endregion

        #region 生成普通二维码===========================
        public string getdiyurl(string sceneid)
        {
            var qrcode = qr_DiyCodeService.Instance.Get_SingleEntity_byWhere(qr_DiyCode._.scene_id == sceneid);
            if (qrcode != null)
                return qrcode.qrcode_url;
            return "";
        }
        #endregion

        #region 导出成Excel表格==========================

        protected void btnDownload_Click(object sender, EventArgs e)
        {
            int sucCount = 0;
            int errorCount = 0;
            try
            {
                DataSet ds = new DataSet();
                DataTable table = new DataTable();
                string sql = "";
                if (ddl_IsSenate.SelectedValue == "true")
                {
                    //导出有参二维码 qr_QrCode
                    sql = "select qat.A_Name,qat.A_Desc ,qat.A_Manager,qat.A_wxQrCodeID,qat.A_wxSceneID,qat.A_wxTitle,qat.A_wxDesc,qr.qrcode_url from qr_Activity qat  inner join qr_QrCode qr on qat.A_wxSceneID=qr.scene_id";
                }
                else
                {
                    //导出无参二维码 qr_DiyCode
                    sql = "select qat.A_Name,qat.A_Desc ,qat.A_Manager,qat.A_wxQrCodeID,qat.A_wxSceneID,qat.A_wxTitle,qat.A_wxDesc,qr.qrcode_url from qr_Activity qat  inner join qr_DiyCode qr on qat.A_wxSceneID=qr.scene_id";
 
                }
                table = DbSession.Default.FromSql(sql).ToTable();
                table.TableName = "qr_Activity";
                ds.Tables.Add(table);

                ExcelExportProvider provider = ExcelExportConfiguration.Current.ExcelConfigs["Activityinfo"];
                // 导入配置文件验证
                ConfigExportValidate(provider, ds, "Activityinfo");
                string fullPath;
                string templateFile = null;
                if (!string.IsNullOrEmpty(templateFile))
                    fullPath = templateFile;
                else if (!string.IsNullOrEmpty(provider.TemplateFile))
                {
                    HttpContext context = HttpContext.Current;
                    if (context != null)
                    {
                        fullPath = context.Server.MapPath("~/" + provider.TemplateFile);
                    }
                    else
                    {
                        fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, provider.TemplateFile);
                    }
                }
                else
                    throw new Exception("参数excelFile及预设的TemplateFile都为空，无法打开Excel文件");

                ExcelUtilities excelUtils = new ExcelUtilities();
                excelUtils.ExportExcel(Response, string.Format("ExportCode_{0}", DateTime.Now.ToString("yyyy-MM-dd")), ds, "Activityinfo");
                sucCount += 1;
            }
            catch (Exception ex)
            {
                //WriteLog.WriteError(ex.ToString());
                ComLib.LogLib.Log4NetBase.Log(ex.Message + ex.StackTrace);
                JscriptMsg("下载时发生错误请联系管理员！", searchURL, "Error");
            }
            //记录日志
            AddAdminLog(DTEnums.ActionEnum.Export.ToString(), "导出NC用户信息" + sucCount + "条，失败" + errorCount + "条");

            JscriptMsg("导出成功" + sucCount + "条，失败" + errorCount + "条！", searchURL, "Success");
        }

        protected void ConfigExportValidate(ExcelExportProvider provider, DataSet container, string typeName)
        {
            ///验证数据容器中是否存在DataTable
            if (container.Tables.Count == 0) throw new Exception("DataSet对象容器中没有任何DataTable对象!");
            ///验证导入配置中的配置节是否存在
            if (provider == null) throw new Exception(string.Format("配置中不存在类型为:{0}的导入配置项!", typeName));
            ///验证配置节中是否包含至少1个worksheet
            if (provider.Worksheets == null || provider.Worksheets.Count == 0) throw new Exception(string.Format("配置中类型为:{0}的配置节中不包含Worksheet的定义", typeName));
            // 验证数据容器中存在配置节中配置的datatable
            foreach (var worksheet in provider.Worksheets)
            {
                foreach (Area area in worksheet.Areas)
                    if (!container.Tables.Contains(area.DataTable))
                        throw new Exception(string.Format("DataTable中不包含表 {0}", area.DataTable));
            }
        }
        #endregion

        #region 导出二维码图片===========================
        /// <summary>
        /// 导出二维码图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void exportIMG_Click(object sender, EventArgs e)
        {
            #region 根据二维码类型导出二维码图片
            if (ddl_IsSenate.SelectedValue == "true")
            {
                #region 微信二维码
                var info = "";
                try
                {
                    #region 初始化变量
                    int SuccessCount = 0;
                    int ErroCount = 0;
                    int HttpCode = 0;
                    WebClient my = new WebClient();
                    #endregion

                    #region 查询微信二维码列表
                    var actlist = qr_ActivityService.Instance.Get_Entity_byWhere(qr_Activity._.isSenate == 1 && qr_Activity._.A_RuleText == "南区红包活动", qr_Activity._.ActivityID.Asc);//Get_AllData_List();qr_Activity._.ActivityID == 7211
                    ComLib.LogLib.Log4NetBase.Log("1-1、---------------导出1000图片开始,总共::" + actlist.Count + "条数据---------------");
                    //string virtulPath = "/upload/1000img/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("dd");
                    //var path = System.Web.HttpContext.Current.Request.MapPath("/upload/1000img/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("dd") + "/");

                    string virtulPath = "/upload/1000img/" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    var path = System.Web.HttpContext.Current.Request.MapPath(virtulPath + "/");
                    //检查保存的物理路径是否存在，不存在则创建\upload\1003img\201609\02
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //2.Zip打包路径 
                    string zipPath = Utils.GetMapPath(virtulPath);
                    //3.保存图片
                    #region 循环遍历保存图片
                    for (int i = 0; i < actlist.Count; i++)
                    {
                        var o = actlist[i];
                        bool result = false;
                        ComLib.LogLib.Log4NetBase.Log("1-2、---------------正在执行第(" + i + ")条数据---------------");

                        #region 查询关联表qr_Type == 1000
                        var entity = qr_QrCodeRelateService.Instance.Get_SingleEntity_byWhere(
                            qr_QrCodeRelate._.qr_Type == 1000 && qr_QrCodeRelate._.IsDelete == false
                            && qr_QrCodeRelate._.rel_Code == o.ActivityID);
                        #endregion

                        if (entity != null)
                        {                            
                            #region 查询微信url，保存图片进文件夹
                            info = "活动ID:" + o.ActivityID + "//活动名称:" + o.A_Name;
                            //微信二维码表
                            var qrcode = qr_QrCodeService.Instance.Get_SingleEntity_byWhere(qr_QrCode._.id == entity.qr_CodeID);
                            if (qrcode != null)
                            {
                                #region 检验URL是否可访问
                                HttpCode = zip_http.GetStatusCode(qrcode.qrcode_url);
                                
                                if (HttpCode == 200)
                                {
                                    byte[] mybyte;
                                    mybyte = my.DownloadData(qrcode.qrcode_url);
                                    MemoryStream ms = new MemoryStream(mybyte);
                                    System.Drawing.Image img;
                                    img = System.Drawing.Image.FromStream(ms);                                    
                                    //string newFileName = path + o.ActivityID + "-" + o.A_Name.Replace("?", "").Replace("？", "").Replace("<", "").Replace(">", "").Replace(":", "") + ".png"; //文件名
                                    string newFileName = path + o.A_Name.Replace("?", "").Replace("？", "").Replace("<", "").Replace(">", "").Replace(":", "") + ".png"; //文件名
                                    string newpath = newFileName.ToString().Trim();
                                    img.Save(newpath, ImageFormat.Png);   //保存
                                    //下面直接输出
                                    //Response.ClearContent();
                                    //Response.ContentType = "image/gif";
                                    //Response.BinaryWrite(mybyte);
                                    result = true;
                                }
                                else
                                {
                                    result = false;
                                    //ErroCount += 1;//不可访问也失败
                                }
                                #endregion
                            }
                            else
                            {
                                result = false;
                                //ErroCount += 1;//qr_DiyCode没有记录也失败
                                ComLib.LogLib.Log4NetBase.Log("0-0、---------------导出1000图片失败::qr_DiyCode没有记录" + info + "---------------");
                            }
                            if (result == true)
                            {
                                SuccessCount += 1;
                                ComLib.LogLib.Log4NetBase.Log("1-3、---------------导出1000图片成功::" + info + "---------------");
                            }
                            else
                            {
                                ErroCount += 1;
                                ComLib.LogLib.Log4NetBase.Log("1-3、---------------导出1000图片失败::" + info + "---------------");
                            }
                            #endregion
                        }
                        else
                        {
                            ErroCount += 1;//qr_QrCodeRelate没关联记录也失败
                            ComLib.LogLib.Log4NetBase.Log("0-0、---------------导出1000图片失败::qr_QrCodeRelate没关联记录;活动ID:" + o.ActivityID + "---------------");
                        }
                    }
                    #endregion

                    //4.打包图片成zip文件
                    #region 片成zip文件
                    zip_http.ZipFolderContents(path, zipPath + ".zip");
                    #endregion
                    //5、通知浏览器下载文件而不是打开  
                    #region 浏览器下载文件
                    //以字符流的形式下载文件  
                    FileStream fs = new FileStream(zipPath + ".zip", FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd") + "微信二维码图片.zip", System.Text.Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    //Response.End();
                    #endregion
                    ComLib.LogLib.Log4NetBase.Log("1-4、---------------导出1000图片结束！成功" + SuccessCount + "条；失败" + ErroCount + "条---------------");
                    JscriptMsg("导出1000图片结束！成功" + SuccessCount + "条；失败" + ErroCount + "条---------------", "List.aspx?isSenate=true", "Success");
                    #endregion
                }
                catch (Exception ex)
                {
                    ComLib.LogLib.Log4NetBase.Log("Exception、---------------导出1000图片异常错误:" + ex.Message + ex.StackTrace + info + "---------------");
                    JscriptMsg("导出图片错误请联系管理员！", "List.aspx?isSenate=true", "Error");
                }
                #endregion
            }
            else if (ddl_IsSenate.SelectedValue =="false")
            {
                #region 普通二维码
                var info = "";
                try
                {
                    #region 初始化变量

                    int SuccessCount = 0;
                    int ErroCount = 0;
                    WebClient my = new WebClient();
                    int HttpCode = 0;
                    #endregion

                    #region 查询普通二维码列表
                    var actlist = qr_ActivityService.Instance.Get_Entity_byWhere(qr_Activity._.isSenate == 0, qr_Activity._.ActivityID.Asc);//Get_AllData_List();
                    ComLib.LogLib.Log4NetBase.Log("2-1、---------------导出1003图片开始,总共::" + actlist.Count + "条数据---------------");

                    string virtulPath = "/upload/1003img/" + DateTime.Now.ToString("yyyyMM") + "/" + DateTime.Now.ToString("dd");
                    var path = System.Web.HttpContext.Current.Request.MapPath(virtulPath + "/");

                    //1.检查保存图片的物理路径是否存在，不存在则创建
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //2.Zip打包路径 
                    string zipPath = Utils.GetMapPath(virtulPath);
                    //3.保存图片
                    #region 循环遍历保存图片
                    for (int i = 0; i < actlist.Count; i++)
                    {
                        var o = actlist[i];
                        bool result = false;
                        ComLib.LogLib.Log4NetBase.Log("2-2、---------------正在执行第(" + i + ")条数据---------------");

                        #region 查询关联表qr_Type == 1003
                        var entity = qr_QrCodeRelateService.Instance.Get_SingleEntity_byWhere(
                            qr_QrCodeRelate._.qr_Type == 1003 && qr_QrCodeRelate._.IsDelete == false
                            && qr_QrCodeRelate._.rel_Code == o.ActivityID);
                        #endregion

                        if (entity != null)
                        {
                            #region 查询普通url，保存图片进文件夹
                            info = "活动ID:" + o.ActivityID + "//活动名称:" + o.A_Name;
                            //普通二维码表
                            var qrcode = qr_DiyCodeService.Instance.Get_SingleEntity_byWhere(qr_DiyCode._.id == entity.qr_CodeID);
                            if (qrcode != null)
                            {

                                #region 检验URL是否可访问
                                HttpCode = zip_http.GetStatusCode(qrcode.qrcode_url);
                                if (HttpCode == 200)
                                {
                                    byte[] mybyte;
                                    mybyte = my.DownloadData(qrcode.qrcode_url);
                                    MemoryStream ms = new MemoryStream(mybyte);
                                    System.Drawing.Image img;
                                    img = System.Drawing.Image.FromStream(ms);
                                    string newFileName = path + o.ActivityID + "-" + o.A_Name.Replace("?", "").Replace("？", "").Replace("<", "").Replace(">", "").Replace(":", "") + ".png"; //文件名
                                    string addzippath = o.ActivityID + "-" + o.A_Name.Replace("?", "").Replace("？", "").Replace("<", "").Replace(">", "").Replace(":", "") + ".png";
                                    string newpath = newFileName.ToString().Trim();
                                    img.Save(newpath, ImageFormat.Png);   //保存                                        
                                    result = true;
                                }
                                else
                                {
                                    result = false;
                                    //ErroCount += 1;//不可访问也失败
                                }
                                #endregion
                            }
                            else
                            {
                                result = false;
                                //ErroCount += 1;//qr_DiyCode没有记录也失败
                                ComLib.LogLib.Log4NetBase.Log("0-0、---------------导出1003图片失败::qr_DiyCode没有记录" + info + "---------------");
                            }
                            if (result == true)
                            {
                                SuccessCount += 1;
                                ComLib.LogLib.Log4NetBase.Log("2-3、---------------导出1003图片成功::" + info + "---------------");
                            }
                            else
                            {
                                ErroCount += 1;
                                ComLib.LogLib.Log4NetBase.Log("2-3、---------------导出1003图片失败::" + info + "---------------");
                            }
                            #endregion
                        }
                        else
                        {
                            ErroCount += 1;//qr_QrCodeRelate没关联记录也失败
                            ComLib.LogLib.Log4NetBase.Log("0-0、---------------导出1003图片失败::qr_QrCodeRelate没关联记录;活动ID:" + o.ActivityID + "---------------");
                        }
                    }
                    #endregion
                    //4.打包图片成zip文件
                    #region 片成zip文件
                    zip_http.ZipFolderContents(path, zipPath + ".zip");
                    #endregion
                    //5、通知浏览器下载文件而不是打开  
                    #region 浏览器下载文件
                    //以字符流的形式下载文件  
                    FileStream fs = new FileStream(zipPath + ".zip", FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd") + "普通二维码图片.zip", System.Text.Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    //Response.End();
                    #endregion

                    ComLib.LogLib.Log4NetBase.Log("2-4、---------------导出1003图片结束！成功" + SuccessCount + "条；失败" + ErroCount + "条---------------");
                    JscriptMsg("导出1003图片结束！成功" + SuccessCount + "条；失败" + ErroCount + "条---------------", "List2.aspx?isSenate=false", "Success");
                    #endregion
                }
                catch (Exception ex)
                {
                    ComLib.LogLib.Log4NetBase.Log("Exception、---------------导出1003图片异常错误:" + ex.Message + ex.StackTrace + info + "---------------");
                    JscriptMsg("导出图片错误请联系管理员！", "List2.aspx?isSenate=false", "Error");
                }
                #endregion
            }
            #endregion
        }         
        #endregion

        #region 下拉框改变事件===========================
        protected void ddl_IsSenate_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.isSenate = this.ddl_IsSenate.SelectedValue.ToLower();
            this.A_Name = txtA_Name.Text;
            this.A_Manager = txtA_Manager.Text;          
            Response.Redirect(searchURL);
        }
        #endregion

        #region 批量更新二维码===========================
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            bool result5 = false;
            int SuccessCount = 0;//成功条数
            int ErrorCount = 0;//失败条数
            var nclist = qr_ActivityService.Instance.Get_Entity_byWhere(qr_Activity._.isneedupdate==true, null);//qr_Activity._.A_Desc=="活动正在火热进行中，快来参加吧！！！"
            ComLib.LogLib.Log4NetBase.Log("3、==========================更新南区红包活动二维码===========数量:" + nclist.Count);
            string currenturl = "http://mjnsouth.esmartwave.cn/default.aspx?aid=$openId=####";
            nclist.ForEach(o =>
            {
                currenturl = o.A_currentUrl;
                try
                {
                    #region 操作更新二维码

                    #region 单图文
                    var extra = new List<extra>() {                                        
                                        new ShareMarking.Interface.extra { 
                                            title = Regex.Replace(o.A_wxTitle, @"\s", ""),
                                            shortdesc = Regex.Replace(o.A_Desc, @"\s", ""), 
                                            linkurl = currenturl,
                                            picurl =diyhttp+ "/images/red.jpg"
                                        }
                                    };

                    var message = new ShareMarking.Interface.message2()
                    {
                        id = o.A_wxQrCodeID,
                        title = o.A_Name,
                        remark = o.A_Name + "的二维码",
                        sacode = "test",
                        extra = extra
                    };
                    #endregion

                    #region vigo接口申请
                    var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                    var resultentity = vigo.UpdateQrcode(message);
                    if (resultentity.IndexOf("成功") > 0)
                    {
                        #region 更新单图文活动
                        //var entity = new qr_Activity();
                        //o.A_Name = o.A_Name;
                        //o.A_Desc = o.A_Desc; //row[3].ToString().Trim();//活动描述
                        //o.A_Manager = o.A_Manager;//负责人
                        //o.A_wxTitle = o.A_wxTitle;//
                        o.A_wxUrl = currenturl;//活动中链接;
                        o.A_wxbeforeUrl = currenturl;//活动前链接;
                        o.A_wxafterUrl = currenturl;//活动后链接;
                        //o.A_currentUrl = currenturl;//当前使用的URL
                        o.DateModified = DateTime.Now;
                        //o.A_wxDesc = o.A_wxDesc;
                        //o.A_wxUrl = o.A_wxUrl;//活动中链接;
                        //o.A_wxbeforeUrl = o.A_wxbeforeUrl;//活动前链接;
                        //o.A_wxafterUrl = o.A_wxafterUrl;//活动后链接;
                        //o.A_SaCode = "";
                        //o.A_StartTime = o.A_StartTime;
                        //o.A_EndTime = o.A_EndTime;
                        //o.A_currentUrl = o.A_currentUrl;//当前使用的URL
                        o.DateModified = DateTime.Now;
                        o.isneedupdate = false;
                        result5 = qr_ActivityService.Instance.Update_Entity(o);
                        //ComLib.LogLib.Log4NetBase.Log("有相同重复活动名称：" + o.A_Name);
                        if (result5)
                        {
                            SuccessCount += 1;
                            //AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_Activity:" + o.ActivityID); //记录日志
                        }
                        
                        #endregion
                    }
                    else
                    {

                        ErrorCount += 1;//已经添加
                    }
                    #endregion

                    #endregion
                }
                catch (Exception ex)
                {
                    ComLib.LogLib.Log4NetBase.Log("更新一个二维码错误::::" + ex.Message + ex.StackTrace);
                }
            });
            JscriptMsg("更新成功" + SuccessCount + "条，失败" + ErrorCount + "条！", "List.aspx?isSenate=true", "Success");
            ComLib.LogLib.Log4NetBase.Log("更新结束，成功：" + SuccessCount + "条，失败：" + ErrorCount + "条！");
        }
        #endregion
    }

}